const express = require('express')
const pool = require('../db')
const router = express.Router()

//获取文章分类列表
router.get('/cates', (req, res) => {
  pool.query('select * from article_cate', (err, results) => {
    // console.log(results)
    if (results) {
      res.send({
        status: 0,
        message: '获取文章分类成功',
        data: results,
      })
    } else {
      res.send({
        status: 1,
        message: '获取文章分类失败',
      })
    }
  })
})

router.post('/addcates', (req, res) => {
  pool.query('insert into article_cate set ?', req.body, (err, results) => {
    // console.log(results)
    if (results && results.affectedRows > 0) {
      res.send({
        status: 0,
        message: '添加分类成功'
      })
    } else {
      res.send({
        status: 1,
        message: '添加分类失败'
      })
    }
  })
})

module.exports = router
